package com.wander.patterns.structure.composit;


import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: zhuyong
 * @create: 2019-09-04 11:33
 **/
public interface IFile {
    void killVirus();//杀毒


    class ImageFile implements IFile{
        private String name;

        public ImageFile(String name) {
            this.name = name;
        }

        @Override
        public void killVirus() {
            System.out.println("图像:"+this.name+"文件杀毒处理方式");
        }
    }
    class Mp4File implements IFile{
        private String name;

        public Mp4File(String name) {
            this.name = name;
        }

        @Override
        public void killVirus() {
            System.out.println("MP4:"+this.name+"文件杀毒处理方式");
        }
    }
    class TxtFile implements IFile{
        private String name;

        public TxtFile(String name) {
            this.name = name;
        }

        @Override
        public void killVirus() {
            System.out.println("Txt:"+this.name+"文件杀毒处理方式");
        }
    }

    //文件夹
    class Folder implements IFile{
        private String name;
        //当前文件夹下的子节点列表
        private List<IFile> children = new ArrayList<IFile>();

        public Folder(String name) {
            this.name = name;
        }
        @Override
        public void killVirus() {
            System.out.println("文件夹:"+name+"准备杀毒...");
            children.forEach(f->{
                f.killVirus();
            });
        }
        void add(IFile file){
            children.add(file);
        }

        void remove(IFile file){
            children.remove(file);
        }

        IFile getChild(int index){
            return children.get(index);
        }

    }

}
